package vip.xiaonuo.supplier.modular.business.businessdetail.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.pojo.CommonResult;
import vip.xiaonuo.supplier.modular.business.businessdetail.entity.SupplierBusinessDetail;
import vip.xiaonuo.supplier.modular.business.businessdetail.param.SupplierBusinessDetailAddParam;
import vip.xiaonuo.supplier.modular.business.businessdetail.param.SupplierBusinessDetailEditParam;
import vip.xiaonuo.supplier.modular.business.businessdetail.param.SupplierBusinessDetailIdParam;
import vip.xiaonuo.supplier.modular.business.businessdetail.param.SupplierBusinessDetailPageParam;
import vip.xiaonuo.supplier.modular.business.businessdetail.service.SupplierBusinessDetailService;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import java.util.List;

/**
 * 业务明细表控制器
 *
 * @author Mr.wu
 * @date  2025/03/26 11:23
 */
@Tag(name = "业务明细表控制器")
@RestController
@Validated
public class SupplierBusinessDetailController {

    @Resource
    private SupplierBusinessDetailService supplierBusinessDetailService;

    /**
     * 获取业务明细表分页
     *
     * @author Mr.wu
     * @date  2025/03/26 11:23
     */
    @Operation(summary = "获取业务明细表分页")
    @SaCheckPermission("/supplier/business/businessdetail/page")
    @GetMapping("/supplier/business/businessdetail/page")
    public CommonResult<Page<SupplierBusinessDetail>> page(SupplierBusinessDetailPageParam supplierBusinessDetailPageParam) {
        return CommonResult.data(supplierBusinessDetailService.page(supplierBusinessDetailPageParam));
    }

    /**
     * 添加业务明细表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:23
     */
    @Operation(summary = "添加业务明细表")
    @CommonLog("添加业务明细表")
    @SaCheckPermission("/supplier/business/businessdetail/add")
    @PostMapping("/supplier/business/businessdetail/add")
    public CommonResult<String> add(@RequestBody @Valid SupplierBusinessDetailAddParam supplierBusinessDetailAddParam) {
        supplierBusinessDetailService.add(supplierBusinessDetailAddParam);
        return CommonResult.ok();
    }

    /**
     * 编辑业务明细表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:23
     */
    @Operation(summary = "编辑业务明细表")
    @CommonLog("编辑业务明细表")
    @SaCheckPermission("/supplier/business/businessdetail/edit")
    @PostMapping("/supplier/business/businessdetail/edit")
    public CommonResult<String> edit(@RequestBody @Valid SupplierBusinessDetailEditParam supplierBusinessDetailEditParam) {
        supplierBusinessDetailService.edit(supplierBusinessDetailEditParam);
        return CommonResult.ok();
    }

    /**
     * 删除业务明细表
     *
     * @author Mr.wu
     * @date  2025/03/26 11:23
     */
    @Operation(summary = "删除业务明细表")
    @CommonLog("删除业务明细表")
    @SaCheckPermission("/supplier/business/businessdetail/delete")
    @PostMapping("/supplier/business/businessdetail/delete")
    public CommonResult<String> delete(@RequestBody @Valid @NotEmpty(message = "集合不能为空")
                                                   List<SupplierBusinessDetailIdParam> supplierBusinessDetailIdParamList) {
        supplierBusinessDetailService.delete(supplierBusinessDetailIdParamList);
        return CommonResult.ok();
    }

    /**
     * 获取业务明细表详情
     *
     * @author Mr.wu
     * @date  2025/03/26 11:23
     */
    @Operation(summary = "获取业务明细表详情")
    @SaCheckPermission("/supplier/business/businessdetail/detail")
    @GetMapping("/supplier/business/businessdetail/detail")
    public CommonResult<SupplierBusinessDetail> detail(@Valid SupplierBusinessDetailIdParam supplierBusinessDetailIdParam) {
        return CommonResult.data(supplierBusinessDetailService.detail(supplierBusinessDetailIdParam));
    }

    /**
     * 获取业务明细列表
     *
     * @author Mr.wu
     * @date  2025/03/31 11:23
     */
    @Operation(summary = "获取业务明细列表")
    @SaCheckPermission("/supplier/business/businessdetail/list")
    @GetMapping("/supplier/business/businessdetail/list")
    public CommonResult<List<SupplierBusinessDetail>> list(SupplierBusinessDetailPageParam supplierBusinessDetailPageParam) {
        return CommonResult.data(supplierBusinessDetailService.detailList(supplierBusinessDetailPageParam));
    }
}
